<template>
    <div class="container">
        <h3>生产管理</h3>
        <el-tabs v-model="activeName" type="border-card" style="margin-top:20px;" @tab-click="handleClick">
            <el-tab-pane v-if='switchHeadTab == "生产系统"' label="提取饮片" name="提取饮片">
                <el-row style="margin: 10px 0 20px 0">
                    <el-col :span="7">
                        <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchName1">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="handleSearch1">搜索</el-button>
                        </el-input>
                    </el-col>
                    <router-link :to="{path:'/production/addProduction',query: {type: '提取饮片'}}" v-if="check"><el-button type="primary" style="float:right; margin-right: 10px">新增生产</el-button></router-link>
                </el-row>

                <el-table
                    :data="tableData"
                    border
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                >
                    <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                    <el-table-column prop="standard" sortable label="标准类型"></el-table-column>
                    <el-table-column prop="batch" sortable label="生产批号"></el-table-column>
                    <el-table-column prop="time" sortable label="生产日期"></el-table-column>
                    <el-table-column prop="totalNumber" sortable label="生产数量">
                        <template slot-scope="scope">
                            {{scope.row.totalNumber}}{{scope.row.units}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="surplusNumber" sortable label="剩余量">
                        <template slot-scope="scope">
                            {{scope.row.surplusNumber}}{{scope.row.units}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                    <el-table-column label="操作" width="150" align="center">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="handleView(scope.$index, scope.row)"
                            >查看</el-button>
                            <el-button type="text" v-if="scope.row.isRecall == 0">
                                <el-dropdown style="color: #409EFF; font-size:12px">
                                    <span class="el-dropdown-link">
                                        更多
                                    </span>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item >
											<div @click="handleEdit(scope.$index, scope.row)">
												<el-button
                                                type="text"
                                                v-if="check1"
                                                style="color: #666"
												>编辑</el-button>
											</div>

                                        </el-dropdown-item>
                                        <el-dropdown-item>
											<div @click="handleFrmLoss(scope.$index, scope.row)">
												<el-button
												    type="text"
												    v-if="check2"
												    style="color: #666"
												>调整产量</el-button>
											</div>
                                        </el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </el-button>
                            <el-button
                                v-if="scope.row.isRecall == 1"
                                type="info"
                                disabled
                            >已召回</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize1" @current-change="handleCurrentChange1" :total="total1" :current-page.sync="currentPage1" style="margin-top:20px"></el-pagination>
            </el-tab-pane>
			<el-tab-pane v-if='switchHeadTab == "生产系统"' label="配方颗粒(浸膏粉)" name="配方颗粒(浸膏粉)">
			    <el-row style="margin: 10px 0 20px 0">
			        <el-col :span="7">
			            <el-input style="border-radius: 0 5px 5px 0;width:300px;" placeholder="请输入关键词" v-model.trim="searchName3">
			                <i slot="prefix" class="el-input__icon el-icon-search"></i>
			                <el-button slot="append" @click="handleSearch3">搜索</el-button>
			            </el-input>
			        </el-col>
			        <router-link :to="{path:'/production/addProduction',query: {type: '配方颗粒(浸膏粉)'}}"><el-button type="primary" style="float:right; margin-right: 10px">新增生产</el-button></router-link>
			    </el-row>

			    <el-table
			        :data="tableData"
			        border
			        ref="multipleTable"
			        header-cell-class-name="table-header"
			    >
			        <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                    <el-table-column prop="standard" sortable label="标准类型"></el-table-column>
			        <el-table-column prop="batch" sortable label="生产批号"></el-table-column>
			        <el-table-column prop="time" sortable label="生产日期"></el-table-column>
			        <el-table-column prop="totalNumber" sortable label="生产数量">
			            <template slot-scope="scope">
			                {{scope.row.totalNumber}}{{scope.row.units}}
			            </template>
			        </el-table-column>
			        <el-table-column prop="surplusNumber" sortable label="剩余量">
			            <template slot-scope="scope">
			                {{scope.row.surplusNumber}}{{scope.row.units}}
			            </template>
			        </el-table-column>
                    <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
			        <el-table-column label="操作" width="150" align="center">
			            <template slot-scope="scope">
			                <el-button
			                    type="text"
			                    @click="handleView(scope.$index, scope.row)"
			                >查看</el-button>
			                <el-button type="text" v-if="scope.row.isRecall == 0">
			                    <el-dropdown style="color: #409EFF; font-size:12px">
			                        <span class="el-dropdown-link">
			                            更多
			                        </span>
			                        <el-dropdown-menu slot="dropdown">
			                            <el-dropdown-item>
			                                <el-button
			                                    type="text"
			                                    v-if="check1"
			                                    @click="handleEdit(scope.$index, scope.row)"
			                                    style="color: #666"
			                                >编辑</el-button>
			                            </el-dropdown-item>
			                            <el-dropdown-item>
			                                <el-button
			                                    type="text"
			                                    v-if="check2"
			                                    @click="handleFrmLoss(scope.$index, scope.row)"
			                                    style="color: #666"
			                                >调整产量</el-button>
			                            </el-dropdown-item>
			                        </el-dropdown-menu>
			                    </el-dropdown>
			                </el-button>
			                <el-button
			                    v-if="scope.row.isRecall == 1"
			                    type="info"
			                    disabled
			                >已召回</el-button>
			            </template>
			        </el-table-column>
			    </el-table>
			    <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize3" @current-change="handleCurrentChange3" :total="total3" :current-page.sync="currentPage3" style="margin-top:20px"></el-pagination>
			</el-tab-pane>
            <el-tab-pane v-if='switchHeadTab == "生产系统"' label="配方颗粒(颗粒)" name="配方颗粒(颗粒)">
                <el-row style="margin: 10px 0 20px 0">
                    <el-col :span="7">
                        <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchName2">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="handleSearch2">搜索</el-button>
                        </el-input>
                    </el-col>
                    <router-link :to="{path:'/production/addProduction',query: {type: '配方颗粒(颗粒)'}}" v-if="check"><el-button type="primary" style="float:right; margin-right: 10px">新增生产</el-button></router-link>
                </el-row>

                <el-table
                    :data="tableData"
                    border
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                >
                    <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                    <el-table-column prop="standard" sortable label="标准类型"></el-table-column>
                    <el-table-column prop="batch" sortable label="生产批号"></el-table-column>
                    <el-table-column prop="time" sortable label="生产日期"></el-table-column>
                    <el-table-column prop="totalNumber" sortable label="生产数量">
                        <template slot-scope="scope">
                            {{scope.row.totalNumber}}{{scope.row.units}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="surplusNumber" sortable label="剩余量">
                        <template slot-scope="scope">
                            {{scope.row.surplusNumber}}{{scope.row.units}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                    <el-table-column label="操作" width="150" align="center">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="handleView(scope.$index, scope.row)"
                            >查看</el-button>
                            <el-button type="text" v-if="scope.row.isRecall == 0">
                                <el-dropdown style="color: #409EFF; font-size:12px">
                                    <span class="el-dropdown-link">
                                        更多
                                    </span>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item>
											<div @click="handleEdit(scope.$index, scope.row)">
												<el-button
													type="text"
													v-if="check1"
													style="color: #666"
												>编辑</el-button>
											</div>
                                        </el-dropdown-item>
                                        <el-dropdown-item>
											<div @click="handleFrmLoss(scope.$index, scope.row)">
												<el-button
                                                type="text"
                                                v-if="check2"

                                                style="color: #666"
												>调整产量</el-button>
											</div>

                                        </el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </el-button>
                            <el-button
                                v-if="scope.row.isRecall == 1"
                                type="info"
                                disabled
                            >已召回</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize2" @current-change="handleCurrentChange2" :total="total2" :current-page.sync="currentPage2" style="margin-top:20px"></el-pagination>
           </el-tab-pane>
            <el-tab-pane v-if='switchHeadTab == "中药饮片"' label="中药饮片(半成品)" name="中药饮片(半成品)">
                <el-row style="margin: 10px 0 20px 0">
                    <el-col :span="7">
                        <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="medicalHerb.keyword">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="getTableData">搜索</el-button>
                        </el-input>
                    </el-col>
                    <router-link :to="{path:'/production/addProduction',query: {type: '中药饮片(半成品)'}}" v-if="check"><el-button type="primary" style="float:right; margin-right: 10px">新增生产</el-button></router-link>
                </el-row>

                <el-table
                    :data="medicalHerb.tableData"
                    border
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                >
                    <el-table-column prop="breedName" sortable label="名称"></el-table-column>
<!--                    <el-table-column prop="standard" sortable label="标准类型"></el-table-column>-->
                    <el-table-column prop="batch" sortable label="生产批号"></el-table-column>
                    <el-table-column prop="time" sortable label="生产日期"></el-table-column>
                    <el-table-column prop="totalNumber" sortable label="生产数量">
                        <template slot-scope="scope">
                            {{scope.row.totalNumber}}{{scope.row.units}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="surplusNumber" sortable label="剩余量">
                        <template slot-scope="scope">
                            {{scope.row.surplusNumber}}{{scope.row.units}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                    <el-table-column label="操作" width="150" align="center">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="handleView(scope.$index, scope.row)"
                            >查看</el-button>
                            <el-button type="text" v-if="scope.row.isRecall == 0">
                                <el-dropdown style="color: #409EFF; font-size:12px">
                                    <span class="el-dropdown-link">
                                        更多
                                    </span>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item >
                                            <div @click="handleEdit(scope.$index, scope.row)">
                                                <el-button
                                                    type="text"
                                                    v-if="check1"
                                                    style="color: #666"
                                                >编辑</el-button>
                                            </div>

                                        </el-dropdown-item>
                                        <el-dropdown-item>
                                            <div @click="handleFrmLoss(scope.$index, scope.row)">
                                                <el-button
                                                    type="text"
                                                    v-if="check2"
                                                    style="color: #666"
                                                >调整产量</el-button>
                                            </div>
                                        </el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </el-button>
                            <el-button
                                v-if="scope.row.isRecall == 1"
                                type="info"
                                disabled
                            >已召回</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination layout="total, prev, pager, next, jumper" :page-size="medicalHerb.pageSize" @current-change="(page)=>{medicalHerb.page = page;getTableData()}" :total="medicalHerb.total" :current-page.sync="medicalHerb.page" style="margin-top:20px"></el-pagination>
            </el-tab-pane>
<!--            <el-tab-pane v-if='switchHeadTab == "中药饮片"' label="直服饮片" name="直服饮片">-->
<!--                <el-row style="margin: 10px 0 20px 0">-->
<!--                    <el-col :span="7">-->
<!--                        <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="medicalHerb.keyword">-->
<!--                            <i slot="prefix" class="el-input__icon el-icon-search"></i>-->
<!--                            <el-button slot="append" @click="getTableData">搜索</el-button>-->
<!--                        </el-input>-->
<!--                    </el-col>-->
<!--                    <router-link :to="{path:'/production/addProduction',query: {type: '直服饮片'}}" v-if="check"><el-button type="primary" style="float:right; margin-right: 10px">新增生产</el-button></router-link>-->
<!--                </el-row>-->

<!--                <el-table-->
<!--                    :data="directlyTakePills.tableData"-->
<!--                    border-->
<!--                    ref="multipleTable"-->
<!--                    header-cell-class-name="table-header"-->
<!--                >-->
<!--                    <el-table-column prop="breedName" sortable label="名称"></el-table-column>-->
<!--                    <el-table-column prop="standard" sortable label="标准类型"></el-table-column>-->
<!--                    <el-table-column prop="batch" sortable label="生产批号"></el-table-column>-->
<!--                    <el-table-column prop="time" sortable label="生产日期"></el-table-column>-->
<!--                    <el-table-column prop="totalNumber" sortable label="生产数量">-->
<!--                        <template slot-scope="scope">-->
<!--                            {{scope.row.totalNumber}}{{scope.row.units}}-->
<!--                        </template>-->
<!--                    </el-table-column>-->
<!--                    <el-table-column prop="surplusNumber" sortable label="剩余量">-->
<!--                        <template slot-scope="scope">-->
<!--                            {{scope.row.surplusNumber}}{{scope.row.units}}-->
<!--                        </template>-->
<!--                    </el-table-column>-->
<!--                    <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>-->
<!--                    <el-table-column label="操作" width="150" align="center">-->
<!--                        <template slot-scope="scope">-->
<!--                            <el-button-->
<!--                                type="text"-->
<!--                                @click="handleView(scope.$index, scope.row)"-->
<!--                            >查看</el-button>-->
<!--                            <el-button type="text" v-if="scope.row.isRecall == 0">-->
<!--                                <el-dropdown style="color: #409EFF; font-size:12px">-->
<!--                                    <span class="el-dropdown-link">-->
<!--                                        更多-->
<!--                                    </span>-->
<!--                                    <el-dropdown-menu slot="dropdown">-->
<!--                                        <el-dropdown-item >-->
<!--                                            <div @click="handleEdit(scope.$index, scope.row)">-->
<!--                                                <el-button-->
<!--                                                    type="text"-->
<!--                                                    v-if="check1"-->
<!--                                                    style="color: #666"-->
<!--                                                >编辑</el-button>-->
<!--                                            </div>-->

<!--                                        </el-dropdown-item>-->
<!--                                        <el-dropdown-item>-->
<!--                                            <div @click="handleFrmLoss(scope.$index, scope.row)">-->
<!--                                                <el-button-->
<!--                                                    type="text"-->
<!--                                                    v-if="check2"-->
<!--                                                    style="color: #666"-->
<!--                                                >调整产量</el-button>-->
<!--                                            </div>-->
<!--                                        </el-dropdown-item>-->
<!--                                    </el-dropdown-menu>-->
<!--                                </el-dropdown>-->
<!--                            </el-button>-->
<!--                            <el-button-->
<!--                                v-if="scope.row.isRecall == 1"-->
<!--                                type="info"-->
<!--                                disabled-->
<!--                            >已召回</el-button>-->
<!--                        </template>-->
<!--                    </el-table-column>-->
<!--                </el-table>-->
<!--                <el-pagination layout="total, prev, pager, next, jumper" :page-size="medicalHerb.pageSize" @current-change="(page)=>{medicalHerb.page = page;getTableData()}" :total="medicalHerb.total" :current-page.sync="medicalHerb.page" style="margin-top:20px"></el-pagination>-->
<!--            </el-tab-pane>-->

        </el-tabs>
        <el-dialog title="调整产量" :visible.sync="dialogFormVisible">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
                <el-row>
                    <el-col :span="16">
                        <el-form-item label="调整日期：" :label-width="formLabelWidth">
                            <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd" v-model="ruleForm.time" style="width: 300px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="实际产量：" prop="newNumber" :label-width="formLabelWidth">
                            <el-input v-model.trim="ruleForm.newNumber" style="width:300px">
                                <template slot="append">
                                    {{ruleForm.units}}
                                </template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="操作人：" prop="relevantUser" :label-width="formLabelWidth">
                            <el-select v-model="ruleForm.relevantUser" filterable placeholder="请选择" value-key="id" @change="changeRelevant" style="width:300px">
                                <el-option
                                    v-for="item in userList"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item"
                                >
                                {{item.name}}
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {manufacture_findByList,manufacture_findById,user_findAll,manufacture_adjust} from "@/request/api";
import { mapState } from 'vuex';
    export default {
        data() {
            return {
                medicalHerb:{
                    tableData:[],
                    page:1,
                    pageSize:10,
                    total:0,
                    keyword:''
                },
                directlyTakePills:{
                    tableData:[],
                },
                check:true,
                check1:true,
                check2:true,
                dialogFormVisible: false,
                searchName1: '',
                searchName2: '',
                searchName3: '',
                activeName: '提取饮片',
                materialType: '提取饮片',
                tableData: [],
                ruleForm: {
                    time: '',
                    relevantUser: '',
                    relevantUserId: '',
                    newNumber: '',
                    units: '',
                },
                rules:{
                    relevantUser: [
                        { required: true, message: '不能为空', trigger: 'change' }
                    ],
                    newNumber: [
                        { required: true, message: '不能为空', trigger: 'blur' }
                    ]
                },
                total1: 0,
                currentPage1:1,
                pagesize1:10,
                total2: 0,
                currentPage2:1,
                pagesize2:10,
                total3: 0,
                currentPage3:1,
                pagesize3:10,
                formLabelWidth: '120px',
                userList: [],
            };
        },
        created(){
            var data = JSON.stringify(this.$store.state.sc)
            var c = "调整产量"
            var b = '编辑'
            var a = '新增'

            if(data.indexOf(c) != -1){
                this.check2 = true
            }else{
                this.check2 = false
            }

            if(data.indexOf(b) != -1){
                this.check1 = true
            }else{
                this.check1 = false
            }

            if(data.indexOf(a) != -1){
                this.check = true
            }else{
                this.check = false
            }
        },
        destroyed: function () {
            this.$store.commit("setStorName","")
        },
        mounted(){

            if(this.$store.state.storName == '提取饮片'){
                this.activeName = '提取饮片'
                this.init1()
            } else if(this.$store.state.storName == '配方颗粒(颗粒)'){
                this.activeName = '配方颗粒(颗粒)'
                this.init2()
            } else if(this.$store.state.storName == '配方颗粒(浸膏粉)'){
                this.activeName = '配方颗粒(浸膏粉)'
                this.init3()
            } else{
                this.init1();
            }
            if(this.switchHeadTab == '中药饮片'){
                this.activeName = '中药饮片(半成品)'
                this.materialType = '中药饮片(半成品)'
                this.getTableData()
            }else{
                this.activeName = '提取饮片'
                this.init1()
            }
        },
        computed:{
            ...mapState(['switchHeadTab'])
        },
        methods: {
            async getTableData(){
                let params = {
                    materialType: this.materialType,
                    searchName: this.medicalHerb.keyword,
                    page: this.medicalHerb.page,
                    pageSize: this.medicalHerb.pageSize
                }
                const res = await manufacture_findByList(params)
                try{
                    if(res && res.code == 200){
                        this.medicalHerb.tableData = res.rows
                        this.medicalHerb.total = res.total
                    }else{
                        this.$message.error(res.data.msg)
                    }
                }catch (e) {
                    this.$message.error(e)
                    throw e
                }
            },
            // 调用接口
            init1(){
                manufacture_findByList({
                    materialType: '提取饮片',
                    searchName: this.searchName1,
                    page: this.currentPage1,
                }).then((res) =>{
                    this.tableData = res.rows
                    this.total1 = res.total
                    for (let i = 0; i < this.tableData.length; i++) {
                      if(this.tableData[i].qualityStandard){
                          this.tableData[i].qualityStandard = this.tableData[i].qualityStandard.substring(0, 5) + "...."
                      }
                      if(this.tableData[i].standard == "1"){
							this.tableData[i].standard = "国标"
						}else if(this.tableData[i].standard == "2"){
							this.tableData[i].standard = "省标"
						}else if(this.tableData[i].standard == "3"){
							this.tableData[i].standard = "省标-北京"
						}else if(this.tableData[i].standard == "4"){
                            this.tableData[i].standard = "省标-上海"
                        }else{
                            this.tableData[i].standard = ""
                        }
                  }
                })
            },
            init2(){
                manufacture_findByList({
                    materialType: '配方颗粒(颗粒)',
                    searchName: this.searchName2,
                    page: this.currentPage2,
                }).then((res) =>{
                    this.tableData = res.rows
                    this.total2 = res.total
                    for (let i = 0; i < this.tableData.length; i++) {
                      if(this.tableData[i].qualityStandard){
                          this.tableData[i].qualityStandard = this.tableData[i].qualityStandard.substring(0, 5) + "...."
                      }
                      if(this.tableData[i].standard == "1"){
							this.tableData[i].standard = "国标"
						}else if(this.tableData[i].standard == "2"){
							this.tableData[i].standard = "省标"
						}else if(this.tableData[i].standard == "3"){
							this.tableData[i].standard = "省标-北京"
						}else if(this.tableData[i].standard == "4"){
                            this.tableData[i].standard = "省标-上海"
                        }else{
                            this.tableData[i].standard = ""
                        }
                  }
                })
            },
            init3(){
                manufacture_findByList({
                    materialType: '配方颗粒(浸膏粉)',
                    searchName: this.searchName3,
                    page: this.currentPage3,
                }).then((res) =>{
                    this.tableData = res.rows
                    this.total3 = res.total
                    for (let i = 0; i < this.tableData.length; i++) {
                      if(this.tableData[i].qualityStandard){
                          this.tableData[i].qualityStandard = this.tableData[i].qualityStandard.substring(0, 5) + "...."
                      }
                      if(this.tableData[i].standard == "1"){
							this.tableData[i].standard = "国标"
						}else if(this.tableData[i].standard == "2"){
							this.tableData[i].standard = "省标"
						}else if(this.tableData[i].standard == "3"){
							this.tableData[i].standard = "省标-北京"
						}else if(this.tableData[i].standard == "4"){
                            this.tableData[i].standard = "省标-上海"
                        }else{
                            this.tableData[i].standard = ""
                        }
                  }
                })
            },
            // tabs
            handleClick(tab, event) {
                this.materialType = tab.name
                this.medicalHerb.keyword = ''
                this.medicalHerb.page = 1
                this.medicalHerb.total = 0
                if (this.materialType == '提取饮片') {
                    this.init1()
                } else if(this.materialType == '配方颗粒(颗粒)') {
                    this.init2()
                }
                 else if(this.materialType == '配方颗粒(浸膏粉)'){
                    this.init3()
                }else if(this.materialType == '中药饮片' || this.materialType == '直服饮片'){
                     this.getTableData()
                }
            },
            // 选择相关人
            changeRelevant(ele){
                // var ids = []
                // var names = []
                // for (let i = 0; i < ele.length; i++) {
                //     ids.push(ele[i].id);
                //     names.push(ele[i].name);
                // }
                this.ruleForm.relevantUserId = ele.id
                this.ruleForm.relevantUser = ele.name
            },
            //中药材编辑
            handleEdit(index,row){
                this.$router.push({
                    path: '/production/editProduction',
                    query: { id: row.id ,type:this.activeName}
                });
            },
            // 查看
            handleView(index,row){
                this.$router.push({
                    path: '/production/viewProduction',
                    query: { id: row.id }
                });
            },
            // 调整产量
            handleFrmLoss(index,row){
                this.dialogFormVisible = true
                user_findAll('').then((res)=>{
                    this.userList = res.data
                })
                manufacture_findById(row.id).then((res) =>{
                    this.ruleForm.id = res.data.id
                    this.ruleForm.useNumber = res.data.useNumber
                    this.ruleForm.units = res.data.units
                    this.ruleForm.type = res.data.type
                    this.ruleForm.surplusNumber = res.data.surplusNumber
                    // this.ruleForm = res.data
                    // this.ruleForm.relevantUser = res.data.principalUser
                })
            },
            // 提交产量
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // console.log(typeof this.ruleForm.useNumber)
                        if (parseInt(this.ruleForm.newNumber) < parseInt(this.ruleForm.useNumber)) {
                            this.$notify.error({
                                title: '提示',
                                message: '实际产量不能小于使用量'+this.ruleForm.useNumber+'',
                                showClose: false,
                                duration:3000
                            });
                            return false;
                        }
                        var parm = {
                            type: this.ruleForm.type,
                            relevanceId: this.ruleForm.id,
                            time: this.ruleForm.time,
                            relevantUser: this.ruleForm.relevantUser,
                            relevantUserId: this.ruleForm.relevantUserId,
                            newNumber: this.ruleForm.newNumber,
                            units: this.ruleForm.units,
                        }
                        manufacture_adjust(parm).then((res) => {
                            this.$notify({
                                title: '提示',
                                message: '添加成功',
                                type: 'success',
                                duration:1000
                            });
                            this.dialogFormVisible = false
                            if (this.materialType == '提取饮片') {
                                this.init1()
                            } else if(this.materialType == '配方颗粒(颗粒)') {
                                this.init2()
                            }else if(this.materialType == '配方颗粒(浸膏粉)') {
                                this.init3()
                            }
                            // else if(this.materialType == '颗粒包装'){
                            //     this.init3()
                            // }
                            this.ruleForm = {}
                        })
                        //  else if(parseInt(this.ruleForm.newNumber) > parseInt(this.ruleForm.surplusNumber)){
                        //     this.$notify.error({
                        //         title: '提示',
                        //         message: '实际产量不能大于剩余量'+this.ruleForm.surplusNumber+'',
                        //         showClose: false,
                        //         duration:3000
                        //     });
                        // }
                    } else {
                        return false;
                    }
                })
            },
            handleSearch1() {
                this.currentPage1 = 1
                this.init1()
            },
            handleSearch2() {
                this.currentPage2 = 1
                this.init2()
            },
            handleSearch3() {
                this.currentPage3 = 1
                this.init3()
            },
            handleCurrentChange1(val){
                this.currentPage1 = val
                this.init1()
            },
            handleCurrentChange2(val){
                this.currentPage2 = val
                this.init2()
            },
            handleCurrentChange3(val){
                this.currentPage3 = val
                this.init3()
            },
        }
    }
</script>

<style scoped>
.el-pagination{
    text-align: center;
}
.el-col{
    margin-bottom: 0;
}
.el-select .el-input {
width: 130px;
}
.input-with-select .el-input-group__prepend {
background-color: #fff;
}
.el-input--small .el-input__inner{
    border-radius: 5px 0 0 5px !important;
    border-right: none;
}
</style>
